package com.sha.mumbailocal.server.corn;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sha.mumbailocal.shared.Pair;
import com.sha.mumbailocal.server.impl.ContentToPersistentObjectTransformer;
import com.sha.mumbailocal.server.impl.CsvContentParser;
import com.sha.mumbailocal.server.impl.GAEDataStorePersister;
import com.sha.mumbailocal.server.impl.UrlContentProvider;

@SuppressWarnings("serial")
public class ERailSchedulePersisterJob extends AbstractContentPersisterJob {

	public ERailSchedulePersisterJob() {
		setContentProvider(new UrlContentProvider(
				"http://erail.in/rail/getTrains.aspx?Station_From=ABH&Station_To=BUD&DataSource=40"));

		CsvContentParser contentParser = new CsvContentParser();
		contentParser.setRecordDelimeter("\\^");
		contentParser.setFieldDelimiter("~");
		contentParser.setFields(new String[] { "trainNo", "trainName",
				"startStationName", "startStationCode", "endStationName",
				"endStationCode", "sourceStationName", "sourceStationCode",
				"destinitionStationName", "destinitionStationCode",
				"departTime", "arrivalTime", "travelTime", "uk", "uk", "uk",
				"uk", "uk", "uk", "uk", "uk", "uk", "uk", "uk", "uk", "uk",
				"uk", "uk", "uk", "uk", "uk", "uk", "uk", "trainAPINo", "uk",
				"uk", "uk", "uk", "uk", "uk", "uk", "uk", "uk", "uk", "uk",
				"uk", "uk", "uk", "uk", "uk", "uk", "uk", "uk", "uk", "uk",
				"uk", "uk", "uk" });
		setContentParser(contentParser);

		List<Pair<String, Map<String, String>>> pairs = new ArrayList<Pair<String, Map<String, String>>>();
		Map<String, String> startStationMap = new HashMap<String, String>();
		startStationMap.put("code", "startStationCode");
		startStationMap.put("name", "startStationName");
		pairs.add(Pair.create(
				"com.sha.mumbailocal.server.model.Station$startStation",
				startStationMap));
		Map<String, String> endStationMap = new HashMap<String, String>();
		endStationMap.put("code", "endStationCode");
		endStationMap.put("name", "endStationName");
		pairs.add(Pair.create(
				"com.sha.mumbailocal.server.model.Station$endStation",
				endStationMap));
		Map<String, String> trainMap = new HashMap<String, String>();
		trainMap.put("number", "trainNo");
		trainMap.put("name", "trainName");
		trainMap.put("apiNumber", "trainAPINo");
		trainMap.put("startStation", "$startStation");
		trainMap.put("endStation", "$endStation");
		pairs.add(Pair.create("com.sha.mumbailocal.server.model.Train$train1",
				trainMap));
		ContentToPersistentObjectTransformer contentTransformer = new ContentToPersistentObjectTransformer(
				pairs);
		setContentTransformer(contentTransformer);

		setContentPersister(new GAEDataStorePersister());
	}

}
